import torch
import torch.nn as nn

#分段功能


MSL = 3  # 预设每段最大大小

def pre(text):
    textsets = []
    text_current = ""
    word_i = 0  # 字指针

    while word_i < len(text):
        if len(text_current) < MSL:
            text_current += text[word_i]
        else:
            textsets.append(text_current)
            text_current = ""
            continue  # 继续下一次循环

        word_i += 1  # 移动字指针

    if text_current:
        while len(text_current)<MSL:
            text_current+='0'
        textsets.append(text_current)  # 添加剩余的段落

    return textsets

text_data = "MSL分割真的必要吗"
data = pre(text_data)
print(data)
